#include <stdio.h>
#include <vector>
#include <algorithm>
#include <utility>

int n, m, k;
std::vector<std::vector<bool> > a(n, std::vector<bool>(m));

bool dfs(std::vector<std::vector<bool> > &a, int i, int j) {
  if (a[i][j]) return false;
  a[i][j] = true;
  if (i == n - 1 && j == m - 1) return true;
  for (int di = -1; di <= 1; di++) {
    for (int dj = -1; dj <= 1; dj++) {
      if (di*di+dj*dj==1 && i+di>=0 && i+di<n && j+dj>=0 && j+dj<m && !a[i+di][j+dj]) {
        bool found = dfs(a, i + di, j + dj);
        if (found) return true;
      }
    }
  }
  return false;
}

bool pathExists(std::vector<std::vector<bool> > a) {
  return dfs(a, 0, 0);
}

int main() {
  scanf("%d %d %d", &n, &m, &k);
  a.resize(n, std::vector<bool>(m));
  std::vector<std::pair<int, int> > steps(k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &steps[i].first, &steps[i].second);
    --steps[i].first;
    --steps[i].second;
    a[steps[i].first][steps[i].second] = true;    
  }
  if(pathExists(a)) {
    puts("0");
    return 0;
  }
  for (int i = k - 1; i >= 0; i--) {
    a[steps[i].first][steps[i].second] = false;
    if(pathExists(a)) {
        printf("%d\n", i + 1);
        return 0;
    }
  }
}
